﻿//-----------------------------------------------------------------------
// <copyright file="Copyright.cs" author="Michael Herndon">
//     Copyright (c) Michael Herndon.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Amplify.Twitter
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.ServiceModel.Security;


	/// <summary>
	/// Manages interacttions that retrieves information on a user, 
	/// his/her friends, followers on twitter. 
	/// </summary>
	public class UserClient : TwitterClient<IUserClient>, IUserClient 
	{


		/// <summary>
		/// Initializes a new instance of the <see cref="UserClient"/> class.
		/// </summary>
		/// <param name="username">The username.</param>
		/// <param name="password">The password.</param>
		public UserClient(string username, string password)
			: base(username, password)
		{ }




		#region IUserClient Members

		/// <summary>
		/// Gets a TwitterList of friends with their information for the specified user. 
		/// </summary>
		/// <returns>returns an array of <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User[] GetFriends()
		{
			return this.GetFriends(this.Username);
		}

		/// <summary>
		/// Gets a TwitterList of friends with their information for the specified user. 
		/// </summary>
		/// <param name="id">The screen name or id of the user.</param>
		/// <returns>returns an array of <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User[] GetFriends(string id)
		{
			return this.GetFriends(id, 0, DateTime.MinValue, true);
		}

		/// <summary>
		/// Gets a TwitterList of friends with their information for the specified user. 
		/// </summary>
		/// <param name="id">The screen name or id of the user.</param>
		/// <param name="page">The page number (for paging). </param>
		/// <param name="since">Specify a search date for all the friends that have joined since.  </param>
		/// <param name="lite">Specify if you wish to have full or limited user information.  </param>
		/// <returns>returns an array of <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User[] GetFriends(string id, int page, DateTime since, bool lite)
		{
			DefaultOptions options = new DefaultOptions() { Since = since};
			try 
			{
				return this.Proxy.GetFriends(id, page, options.SinceValue, lite);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Gets an array of friends with their information for the specified user. 
		/// </summary>
		/// <param name="id">The screen name or id of the user.</param>
		/// <param name="page">The page number (for paging). </param>
		/// <param name="since">Specify a search date for all the friends that have joined since.  </param>
		/// <param name="lite">Specify if you wish to have full or limited user information.  </param>
		/// <returns>returns an array of <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User[] GetFriends(string id, int page, string since, bool lite)
		{
			try
			{
				return this.Proxy.GetFriends(id, page, since, lite);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Gets a TwitterList of people following the user who is currently logged in.
		/// </summary>
		/// <returns>returns an array of <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User[] GetFollowers()
		{
			return this.GetFollowers(this.Username);
		}

		/// <summary>
		/// Gets a TwitterList of people following the specified user.
		/// </summary>
		/// <param name="id">The screen name or id of the user.</param>
		/// <returns>returns an array of <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User[] GetFollowers(string id)
		{
			try 
			{
				return this.Proxy.GetFollowers(id, 0, true);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Gets an array of people following the specified user.
		/// </summary>
		/// <param name="id">The screen name or id of the user.</param>
		/// <param name="page">The page number (for paging). </param>
		/// <param name="lite">Specify if you wish to have full or limited user information.  </param>
		/// <returns>returns an array of <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User[] GetFollowers(string id, int page, bool lite)
		{
			try
			{
				return this.Proxy.GetFollowers(id, page, lite);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Gets an array of featured users
		/// </summary>
		/// <returns>returns a <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User[] GetFeatured()
		{
			try
			{
				return this.Proxy.GetFeatured();
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Shows the extended information of the user that is logged in.
		/// </summary>
		/// <returns>returns a <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User Show()
		{
			try 
			{
				return this.Proxy.Show(this.Username);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Shows the extended information of the specified user.
		/// </summary>
		/// <param name="id">The screen name or id of the user.</param>
		/// <returns>returns a <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User Show(string id)
		{
			try
			{
				return this.Proxy.Show(id);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Shows the extended information if the specified user by email.
		/// </summary>
		/// <param name="email">The email of the user.</param>
		/// <returns>returns a <see cref="Amplify.Twitter.User"/>.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User ShowByEmail(string email)
		{
			try 
			{
				return this.Proxy.ShowByEmail(email);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		#endregion
	}
}
